package com.yonyou.pmclouds.siteinspection.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.inspectitem.entity.InspectItemVO;
import com.yonyou.pmclouds.inspectitem.rmiitf.InspectItemService;
import com.yonyou.pmclouds.siteinspection.entity.SiteInspectionVO;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SiteInspectionInspectItemProcess implements SingleProcessor<SiteInspectionVO> {
    @Autowired
    private InspectItemService itemService;

    @Override
    public void process(SiteInspectionVO vo, SiteInspectionVO orig) throws BusinessException {
        InspectItemVO[] itemVOs = vo.getInspectitems();
        if (ArrayUtils.isEmpty(itemVOs)) {
            return;
        }
        String pk_siteinspection = vo.getPk_siteinspection();
        for (InspectItemVO inspectItemVO : itemVOs) {
            inspectItemVO.setPk_bill(pk_siteinspection);
            inspectItemVO.setPk_project(vo.getPk_project());
            inspectItemVO.setPosition(vo.getPosition());
            inspectItemVO.setLatitude(vo.getLatitude());
            inspectItemVO.setLongitude(vo.getLongitude());
            inspectItemVO.setPk_tenant(vo.getPk_tenant());
            inspectItemVO.setCreator(vo.getCreator());
            inspectItemVO.setCreatorName(vo.getCreator_name());
        }
        // 添加检查项
        itemService.add(itemVOs, vo);
    }

}
